#pragma once

#include <thread>
#include <mutex>
#include <vector>

class CSocks5Thread
{
public:
    CSocks5Thread(int accepted_fd);
    ~CSocks5Thread();
    bool get_is_thread_end() const;
    void join();
    void stop();
private:
    void thread_worker();
    bool send_method_selection(MethodSelection ms);
    bool send_auth_result(unsigned char result);
    bool reply_connect_error(CONNECTErrorCode ec);
    void forword_loop();
private:
    int accepted_fd_;
    int sock_fd_remote_;
    bool is_thread_end_;
    bool is_force_stop_;
    std::shared_ptr<std::thread> theThread_;
};

typedef std::vector<std::shared_ptr<CSocks5Thread> >::const_iterator SOCKSThreadCIter;
typedef std::vector<std::shared_ptr<CSocks5Thread> >::const_iterator SOCKSThreadIter;
